<?php
/**
 * Lookup Model.
 * @package    spf.models.lookup
 * @author     Simon Downes <simon@simondownes.co.uk>
 * @copyright  Copyright &copy; 2007, Simon Downes 
 * @license    http://www.opensource.org/licenses/mit-license.php
 */

/**
 * Lookup Model.
 *
 * @package    spf.models.lookup
 * @author     Simon Downes <simon@simondownes.co.uk>
 * @copyright  Copyright &copy; 2007, Simon Downes 
 * @license    http://www.opensource.org/licenses/mit-license.php
 */
final class Lookup extends SPF_Model {

   /**
    * Constructor.
    *
    * @return  void
    */
   public function __construct( $table_name ) {

      /* construct the parent object */
      parent::__construct($table_name);
      
      $this->add_validation('description', true, 'alphanumeric', ' ');
      
   } // __construct

   /**
    * Destructor.
    *
    * @return  void
    */
   public function __destruct() {
      parent::__destruct();
   }
   
   public function clear( $keep_id = false ) {
       
       parent::clear($keep_id);
       
       $this->active = 1;
       
   } // clear
   
   public static function browse_data( $table_name ) {
   
		if( SPF::$db->has_field($table_name, 'system_type') ) {
			$sql = "SELECT id,
                          description,
                          active,
                          system_type
                     FROM $table_name
                 ORDER BY system_type,
                          description";
		}
		else {
      	$sql = "SELECT id,
                          description,
                          active
                     FROM $table_name
                 ORDER BY description";
      }

      return SPF::$db->get_all($sql);
      
   } // browse_data
   
} // Lookup

?>
